package com.doyens.gmall.product.controller;

import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.*;
import com.doyens.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "商品分类后台接口",description = "商品分类后台")
@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> category1List = manageService.getCategory1();
        return Result.ok(category1List);
    }

    @ApiOperation(notes = "查询二级分类" ,value = "根据一级分类id查询二级分类")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id")Long category1Id){
        List<BaseCategory2> category2List = manageService.getCategory2(category1Id);
        return Result.ok(category2List);
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id")Long category2Id){
        List<BaseCategory3> category3List = manageService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") Long category1Id ,
                               @PathVariable("category2Id") Long category2Id ,
                               @PathVariable("category3Id") Long category3Id){

        return Result.ok(manageService.getAttrInfoList(category1Id,category2Id,category3Id));
    }

    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
        BaseAttrInfo baseAttrInfo = manageService.getBaseAttrInfo(attrId);
        if (baseAttrInfo != null){
            List<BaseAttrValue> baseAttrValueList = manageService.getAttrValueList(attrId);
            return Result.ok(baseAttrValueList);
        }
            return Result.ok();
    }

}
